﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


public partial class user_edit : System.Web.UI.Page
{
    BLL.Business.UserBLL userBLL = new BLL.Business.UserBLL();
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
          DataBindGrid();
    }

    public void DataBindGrid()
    {
        try
        {
            DataSet ds = new DataSet();
            ds = userBLL.SelectAll();

            if ((ds == null) ||
                (ds.Tables.Count == 0) ||
                (ds.Tables.Count == 1 && ds.Tables[0].Rows.Count == 0))
            {
            }
            else
            {
                userList.DataSource = ds;
                userList.DataBind();
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('" + ex.Message.ToString() + "')</script>");
        }
    }
    protected void userList_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "deleteUser")
            {
                int UserId = Int32.Parse(e.CommandArgument.ToString());
                if (userBLL.Delete(UserId))
                {
                    DataBindGrid();
                }
                else
                {
                    Response.Write("<script>alter('出现错误，请检查！')</script>");
                }
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('" + ex.Message.ToString() + "')</script>");
        }
    }
}
